package ioStream.file;

import org.junit.jupiter.api.Test;

import java.io.File;

/**
 * Created with IntelliJ IDEA
 * Description:关于目录方法学习
 * User:22954
 * Date:2024-03-14
 * Time:21:12
 */
@SuppressWarnings("all")
public class DictionaryMethod {
    /*
    public boolean delete()  删除file对象的文件(目录也视为文件)
    public boolean mkdir()  创建一级目录
    public boolean mkdirs()  创建多级目录
     */
    @Test
    public void m1(){//删除文件
        File file = new File("f:/Test/NewFile4.txt");
        if (file.exists()) {
            if (file.delete()) {
                System.out.println("delete successfully !");
            } else {
                System.out.println("delete fail !");
            }
        } else {
            System.out.println("dictionary isn't exist !");
        }
    }
    @Test
    public void m2(){//删除目录
        File file = new File("f:/Test/demo1");
        if (file.exists()) {
            if (file.delete()) {
                System.out.println("delete successfully !");
            } else {
                System.out.println("delete fail !");
            }
        } else {
            System.out.println("dictionary isn't exist !");
        }
    }
    @Test
    public void m3(){//创建一级目录
        File file = new File("f:/Test/demo");
        if (file.exists()) {
            System.out.println("dictionary already exist !");
        } else {
            if(file.mkdir()) {
                System.out.println("create dictionary successfully");
            } else {
                System.out.println("create failed");
            }
        }
    }
    @Test
    public void m4(){//创建多级目录
        File file = new File("f:/Test/demo/a/b/c");
        if (file.exists()) {
            System.out.println("dictionary already exist");
        } else {
            if (file.mkdirs()) {
                System.out.println("create dictionary successfully");
            } else {
                System.out.println("create failed");
            }
        }
    }
}
